﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "DockImpl.h"
#include "IWidget.h"
#include "TransferOwnership.h"
#include "GmStyleSheetHelper.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

using namespace gcmp;
DockImpl::DockImpl(const std::wstring& name, const std::wstring& title, QWidget* parent/* = nullptr*/)
    : QDockWidget(QString::fromStdWString(title), parent)
    , m_name(name)
    , m_pWidget(nullptr)
{
    // Set StyleSheet
    std::wstring styleSheetStr = GmStyleSheetHelper::Instance()->GetCurrentStyleData();
    setStyleSheet(QString::fromStdWString(styleSheetStr));
}

DockImpl::~DockImpl()
{
}

const std::wstring& DockImpl::GetName() const
{
    return m_name;
}

void DockImpl::MoveTo(int x, int y)
{
    QDockWidget::move(x, y);
}

IWidget* DockImpl::GetWidget() const
{
    return m_pWidget;
}

void DockImpl::SetWidget(OwnerPtr<IWidget> opWidget)
{
    m_pWidget = TRANSFER_OWNERSHIP_TO_THIRD_PARTY(opWidget);
    QWidget* pContentWidget = dynamic_cast<QWidget*>(m_pWidget);
    if (pContentWidget)
        QDockWidget::setWidget(pContentWidget);
}

void gcmp::DockImpl::SetTitle(const std::wstring& title)
{
    QDockWidget::setWindowTitle(QString::fromStdWString(title));
}

std::wstring gcmp::DockImpl::GetTitle() const
{
    return QDockWidget::windowTitle().toStdWString();
}

void DockImpl::Show()
{
    QDockWidget::show();
}

void DockImpl::Hide()
{
    QDockWidget::hide();
}

void DockImpl::Raise()
{
    QDockWidget::raise();
}

bool DockImpl::IsHidden() const
{
    return QDockWidget::isHidden();
}

void DockImpl::SetFloating(bool floating)
{
    QDockWidget::setFloating(floating);
}

bool DockImpl::IsFloating() const
{
    return QDockWidget::isFloating();
}
